home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / Tape Stuff / Pascal Strings / Pstrncmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-24  |  684 b   |  36 lines  |  [TEXT/KAHL]

  1. /****************************************************************************
  2.  *
  3.  * FILE:    Pstrncmp.c
  4.  * CREA:    Sven Axelsson, GU
  5.  * MODF:    fredag 13 april 1990 @ 11.52.54
  6.  * HIST:    90-04-13 (1.0)    First version.
  7.  *
  8.  ****************************************************************************/
  9.  
  10. # include    "pstring.h"
  11.  
  12.  
  13. short
  14. Pstrncmp(
  15.     register Str255            s1,
  16.     register Str255            s2,
  17.     short                    n )
  18. {
  19.     register unsigned int    i;
  20.     register short            cmp;
  21.     unsigned int            l1 = s1[0],
  22.                             l2 = s2[0];
  23.  
  24.     
  25.     for( i = 1; i <= l1 && i <= l2 && i <= n; i++ ) {
  26.         cmp = *++s1 - *++s2;
  27.         if( cmp ) {
  28.             return( cmp );
  29.         }
  30.     }
  31.     if( n <= l1 && n <= l2 ) {
  32.         return( 0 );
  33.     } else {
  34.         return( l1 - l2 );
  35.     }
  36. }